package tut.binnaryTree.main;

import tut.binnaryTree.base.BinaryTree;
import tut.binnaryTree.base.DuplicateException;

public class BinnaryTreeTest {

	public static void main(String[] args) throws DuplicateException{
		BinaryTree btree = new BinaryTree();
		System.out.println("Height = " + btree.getHeight());

		int root = 5;
		int left = 0;
		int right = 8;

		btree.insert(root);

		for (int i = left; i <= right; i++) {
			try {
				btree.insert(i);
			} catch (DuplicateException e) {
				System.out.println(e.getMsg());
			}
		}

		System.out.println("Height = " + btree.getHeight());

		int find = 10;
		find = 10; System.out.println("Find " + find + ": " + btree.lookup(find));
		find = 9; System.out.println("Find " + find + ": " + btree.lookup(find));
		find = 8; System.out.println("Find " + find + ": " + btree.lookup(find));
		find = 6; System.out.println("Find " + find + ": " + btree.lookup(find));
		find = 5; System.out.println("Find " + find + ": " + btree.lookup(find));
		find = 1; System.out.println("Find " + find + ": " + btree.lookup(find));
		find = 2; System.out.println("Find " + find + ": " + btree.lookup(find));
		find = 0; System.out.println("Find " + find + ": " + btree.lookup(find));
		find = -2; System.out.println("Find " + find + ": " + btree.lookup(find));

		System.out.println("\n===============\n");
		btree = new BinaryTree();
		btree.insert(5);
		btree.insert(3);
		btree.insert(8);
		btree.insert(1);
		btree.insert(4);
		btree.insert(0);
		btree.insert(2);
		btree.insert(6);
		btree.insert(7);

		System.out.println("Height = " + btree.getHeight());

		find = 0; System.out.println("Find " + find + ": " + btree.lookup(find));
		find = 4; System.out.println("Find " + find + ": " + btree.lookup(find));
		find = 6; System.out.println("Find " + find + ": " + btree.lookup(find));
		find = 9; System.out.println("Find " + find + ": " + btree.lookup(find));

		System.out.println("Find smallest: " + btree.getSmallest().getKey());
		System.out.println("Find right smallest: " + btree.getRightSmallest().getKey());

		System.out.println("\n======== tree browser =======\n");
		System.out.println("left node right"); btree.browser(BinaryTree.LEFT_NODE_RIGHT);
		System.out.println("node left right"); btree.browser(BinaryTree.NODE_LEFT_RIGHT);
		System.out.println("left right node"); btree.browser(BinaryTree.LEFT_RIGHT_NODE);

	}

}
